package com.luobo.shiro.bean;

import java.io.Serializable;

/**
 * 自定义返回值类型
 * @author : AnWen
 * @version :1.0
 * @date : 2019/11/28 11:09
 * @email : anwen375@qq.com
 */
public class Result implements Serializable {

    private static final long serialVersionUID = 1L;

    /** 成功 */
    public static final int success = 1;
    public static final String successMessage ="操作成功";
    /** 错误 */
    public static final int error = 0;
    public static final String errorMessage ="操作失败";


    /** 状态码 */
    private int code;

    /** 返回内容*/
    private String message;

    /**数据对象*/
    private Object data;

    public Result() {
    }

    public Result(int code) {
        this.code = code;
    }

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static Result success() {
        return new Result(success,successMessage);
    }

    public static Result success(String message) {
        return new Result(success,message);
    }

    public static Result success(Object obj) {
        return new Result(success,successMessage,obj);
    }

    public static Result success(String message, Object obj) {
        return new Result(success,message,obj);
    }

    public static Result success(int code, String message, Object obj) {
        return new Result(code,message,obj);
    }

    public static Result error() {
        return new Result(error,errorMessage);
    }

    public static Result error(int code) {
        return new Result(code,errorMessage);
    }

    public static Result error(String message) {
        return new Result(error,message);
    }

    public static Result error(Object obj) {
        return new Result(error,errorMessage,obj);
    }

    public static Result error(int code, String message) {
        return new Result(code,message);
    }

    public static Result error(int code, Object obj) {
        return new Result(code,errorMessage,obj);
    }

    public static Result error(int code, String message, Object obj) {
        return new Result(code,message,obj);
    }



    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }


    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
